package com.fmdj.odr.controller;

import cn.hutool.core.bean.BeanUtil;
import com.fmdj.common.util.CommonResult;
import com.fmdj.odr.controller.form.SearchReviewDriverOrderBillForm;
import com.fmdj.odr.controller.form.SearchSettlementNeedDataForm;
import com.fmdj.odr.controller.form.UpdateBillFeeForm;
import com.fmdj.odr.controller.form.UpdateBillPaymentForm;
import com.fmdj.odr.db.dao.OrderBillDao;
import com.fmdj.odr.service.OrderBillService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/bill")
@Tag(name = "OrderBillController", description = "账单费用模块web接口")
@Slf4j
public class OrderBillController {

    @Autowired
    private OrderBillService orderBillService;

    @PostMapping("/updateBillFee")
    @Operation(summary = "更新账单(同时更新订单以及插入一条分账记录)")
    public CommonResult updateBillFee(@RequestBody @Valid UpdateBillFeeForm form) {
        Map map = BeanUtil.beanToMap(form);
        int rows = orderBillService.updateBillFee(map);
        return CommonResult.ok().put(CommonResult.RETURN_ROW, rows);
    }

    @PostMapping("/searchReviewDriverOrderBill")
    @Operation(summary = "查询司机预览账单信息")
    public CommonResult searchReviewDriverOrderBill(@RequestBody @Valid SearchReviewDriverOrderBillForm form) {
        Map map = BeanUtil.beanToMap(form);
        HashMap result = orderBillService.searchReviewDriverOrderBill(map);
        return CommonResult.ok().put(CommonResult.RETURN_RESULT, result);
    }

    @PostMapping("/updateBillPayment")
    @Operation(summary = "更新账单实付金额")
    public CommonResult updateBillPayment(@RequestBody @Valid UpdateBillPaymentForm form) {
        Map map = BeanUtil.beanToMap(form);
        int rows = orderBillService.updateBillPayment(map);
        return CommonResult.ok().put("rows", rows);
    }
}
